Repository navigation
Support TensorKit v0.17.4 by introducing blockwise _braid! - #92
Conversation
Codecov Report❌ Patch coverage is
🚀 New features to boost your workflow:
|
| function TK.permute_twist!( | ||
| tdst::AbstractBlockTensorMap, tsrc::BlockTensorOrAdjoint, p::Index2Tuple, | ||
| twistmask, backend, allocator | ||
| ) | ||
| @boundscheck TK.spacecheck_transform(TK.permute, space(tdst), space(tsrc), p) | ||
| tsrc′, p′, _, conjsrc = TK._unwrap_source(tsrc, p, nothing, false) | ||
| return _permute_twist_blocks!(tdst, tsrc′, p′, conjsrc, twistmask, backend, allocator) | ||
| end |
There was a problem hiding this comment.
I might be reading this wrong so definitely double-check me here, but isn't this a direct copy of the TensorKit code? Would it be the same if we don't overload here, and overload TK._braid! on blocktensors instead, which I think is the same as the _permute_twist_blocks! function here?
Looking at the TensorKit state a bit more, can we just overload TK._braid! instead of the TK.braid! overloads in the indexmanipulations and that would cover the same thing?
There was a problem hiding this comment.
It's indeed a copy, I just intercept it here and send it directly to the _permute_twist_blocks! below. I could indeed do the blockwise loop through _braid!, again a dense and sparse version (and probably a TensorMap-BlockTensorMap version as well), so TensorKit's permute_twist! catches the individual blocks.
To your last point: correct me if I'm wrong, but I think I could remove more than TK.braid! when overloading TK._braid!. Just looking at the TK code, besides braid! there's also permute! and TO.tensoradd! (and of course permute_twist!) which are overloaded here, and I think those can be removed then? This is definitely not the minimal change needed to introduce the new internal entry point permute_twist! though.
The downside I think to doing one of the two you propose is that we're overwriting something internal that's allowed to change with patch releases, so this might break silently in the future. Worst case, things just start running slower by falling back to the generic case in TensorKit. I'm wondering if there's an easy way to test the dispatch directly.
There was a problem hiding this comment.
Unfortunately all of the options here are overloading or using internal functions from TensorKit. This is probably something we should look into improving in the future, I just never really found the time to do it. Ultimately, I'm definitely in favor of keeping the surface area of that minimal, so if we can just remove many overloads here and only end up needing to overload _braid!, that sounds great
…e! and tensoradd! overloads
permute_twist!_braid!
|
This took a minute, the unwrapping confused me for a bit. There are some comments I left behind to clarify potential future confusions about this, it might save time for anyone (or me again) looking at this. |
lkdvos
left a comment
There was a problem hiding this comment.
Love that this ends up cutting total lines of code in the end, looks great, thanks for fixing!
This PR adds
permute_twist!for block tensors. I kind of just mimicked what's going on in theTO.tensoradd!methods as well as QuantumKitHub/TensorKit.jl#612, especially with the VI alphas and betas, so please check those. If I understand them correctly, they're probably correct 😄Locally, this seemed to fix where it failed, namely a selfdual space like the cartesian one, so that's in the added test. Also added a case where
permute_twist!actually has a twist mask. For cases where it already worked, I guess the fallback within TensorKit was just extremely slow, since I do see a speedup as well. This seemed to also fix the current failing test locally in MPSKit'sclusterexpansion.jl:107where cartesian spaces were used.Edit: I now overload
TK._braid!directly, which allows to remove the overloading ofpermute!,braid!andTO.tensoradd!, as well as supportpermute_twist!.